* Using params and option arrays instead of 4 random parameters like Xml::namespaceSelector did
* Right now it's passing $selectAttribs['name'] to Xml::label, this is done because that's what Xml::namespaceSelector did. However it's wrong since labels associate over ID not NAME. Will fix in the next commit, making sure unit tests stay functional first. This bug has been in Xml::namespaceSelector for a long time but usually unnoticed as people kept either defaults. Although it was easy to get wrong as the NAME was configurable but the ID was hardcoded in Xml::namespaceSelector.
* Deprecated Xml::namespaceSelector and made it cal Html::namespaceSelector
* Follows-up r109974, r109698
* XmlTest.php still runs successfully
using Title::isCssJsSubpage() or checking Title::isWrongCaseCssJsPage().
* (bug 24430) Remove number of column for edit field in preference page.
* Support for the deprecated hook MagicWordMagicWords was removed.
+* The Xml::namespaceSelector method has been deprecated, please use
+ Html::namespaceSelector instead (note that the parameters have changed also).
== Compatibility ==
}
return self::element( 'textarea', $attribs, $spacedValue );
}
+ /**
+ * Build a drop-down box for selecting a namespace
+ *
+ * @param $params array:
+ * - selected: [optional] Id of namespace which should be pre-selected
+ * - all: [optional] Value of item for "all namespaces". If null or unset, <option> is omitted.
+ * - label: text for label to add before the field
+ * @param $selectAttribs array
+ * @return string
+ */
+ public static function namespaceSelector( Array $params = array(), Array $selectAttribs = array() ) {
+ global $wgContLang;
+
+ $selectAttribs = $selectAttribs + array(
+ 'id' => 'mw-namespaceselect',
+ 'name' => 'namespace',
+ );
+ ksort( $selectAttribs );
+
+ // If string only contains digits, convert to clean int. Selected could also
+ // be "all" or "" etc. which needs to be left untouched.
+ // PHP is_numeric() has issues with large strings, PHP ctype_digit has other issues
+ // and returns false for already clean ints. Use regex instead..
+ if ( preg_match( '/^\d+$/', $params['selected'] ) ) {
+ $params['selected'] = intval( $params['selected'] );
+ }
+
+ $options = array();
+ if ( isset( $params['all'] ) ) {
+ $options[$params['all']] = wfMsg( 'namespacesall' );
+ }
+ $options += $wgContLang->getFormattedNamespaces();
+
+ $optionsHtml = array();
+ foreach ( $options as $nsId => $nsName ) {
+ if ( $nsId < NS_MAIN ) {
+ continue;
+ }
+ if ( $nsId === 0 ) {
+ $nsName = wfMsg( 'blanknamespace' );
+ }
+ $optionsHtml[] = Xml::option( $nsName, $nsId, $nsId === $params['selected'] );
+ }
+
+ $ret = Html::openElement( 'select', $selectAttribs )
+ . "\n"
+ . implode( "\n", $optionsHtml )
+ . "\n"
+ . Html::closeElement( 'select' );
+ if ( isset( $params['label'] ) ) {
+ $ret = Xml::label( $params['label'], $selectAttribs['name'] ) . ' ' . $ret;
+ }
+ return $ret;
+ }
/**
* Constructs the opening html-tag with necessary doctypes depending on
* @param $element_name String: value of the "name" attribute of the select tag
* @param $label String: optional label to add to the field
* @return string
+ * @deprecated since 1.19
*/
public static function namespaceSelector( $selected = '', $all = null, $element_name = 'namespace', $label = null ) {
- global $wgContLang;
- $namespaces = $wgContLang->getFormattedNamespaces();
- $options = array();
-
- // Godawful hack... we'll be frequently passed selected namespaces
- // as strings since PHP is such a shithole.
- // But we also don't want blanks and nulls and "all"s matching 0,
- // so let's convert *just* string ints to clean ints.
- if( preg_match( '/^\d+$/', $selected ) ) {
- $selected = intval( $selected );
- }
-
- if( !is_null( $all ) )
- $namespaces = array( $all => wfMsg( 'namespacesall' ) ) + $namespaces;
- foreach( $namespaces as $index => $name ) {
- if( $index < NS_MAIN ) {
- continue;
- }
- if( $index === 0 ) {
- $name = wfMsg( 'blanknamespace' );
- }
- $options[] = self::option( $name, $index, $index === $selected );
- }
-
- $ret = Xml::openElement( 'select', array( 'class' => 'namespaceselector', 'id' => 'namespace',
- 'name' => $element_name ) )
- . "\n"
- . implode( "\n", $options )
- . "\n"
- . Xml::closeElement( 'select' );
- if ( !is_null( $label ) ) {
- $ret = Xml::label( $label, $element_name ) . ' ' . $ret;
- }
- return $ret;
+ wfDeprecated( __METHOD__, '1.19' );
+ return Html::namespaceSelector( array(
+ 'selected' => $selected,
+ 'all' => $all,
+ 'label' => $label,
+ ), array(
+ 'name' => $element_name,
+ 'id' => 'namespace',
+ 'class' => 'namespaceselector',
+ ) );
}
/**